import { EventTouch, _decorator, game } from 'cc';
import { BundleConfig } from '../config/BundleConfig';
import { CommonConfig } from '../config/CommonConfig';
import { GameController } from '../controller/GameController';
import ComponentBase from '../engine/ComponentBase';
import { EngineConfig } from '../engine/EngineConfig';
import { EventManager } from '../engine/EventManager';
import ServerTimer from '../engine/ServerTimer';
import { UIManager } from '../engine/UIManager';
import { ViewLoading } from '../view/ViewLoading';
import { Logger } from '../engine/Logger';
import { GameSocketManager } from '../engine/GameSocketManager';


const { ccclass, property, menu } = _decorator;

@ccclass('main/MainScene')
export class MainScene extends ComponentBase {

    onLoad(): void {
        super.onLoad();
        GameController.instance.init(this);
        EventManager.instance.on(EngineConfig.Event_Type.Event_Click, (event: EventTouch) => {
            GameController.instance.onCLickEvent(event);
        }, this)
        this.showLoadingView();

        // GameSocketManager.instance.getSocketClient("ws://124.0.0.1:9528")
    }

    private showLoadingView() {
        //打开 Loading 界面 
        UIManager.instance.showView(ViewLoading.uiConfig, true, null, true, [CommonConfig.login_UI_Config], BundleConfig.hall, () => {
            UIManager.instance.showView(CommonConfig.login_UI_Config, true, () => {
                UIManager.instance.closeViewByUiConfig(ViewLoading.uiConfig);
            })
        });

        // UIManager.instance.showTips("Are you OK?")
        // UIManager.instance.showCheck("你确定要取消吗?", (isOK: boolean) => {
        //     if (isOK) {
        //         UIManager.instance.showTips("Are you OK?11")
        //     }
        // });  //打开 
    }

    update(dt: number) {
        EventManager.instance.dispatch(EngineConfig.Event_Type.Event_FrameUpdate, dt);
    }

}

